require(['./config'], () => {
    require(['request', 'template', 'url', 'swiper', 'header', 'footer', 'search','cookie'], (request, template, url, Swiper) => {
      class Index {
        constructor () {
          this.brand()
          this.recommend()
          this.getTabs()
          this.swiper()
          this.navs()
        }
        // 品牌旗舰渲染
        brand () {
          $.get(`${url.rap2BaseUrl}/brandshop/get`, resp => {
            if (resp.code === 200) {
              const { list } = resp.body
              console.log(1111)
              $('#brandshopList').html(template('brandshopTemplate', { list }))
            }
          })
        }

        // 推荐渲染
        recommend () {
          $.get(`${url.rap2BaseUrl}/Recommend/get`, resp => {
            if (resp.code === 200) {
              const {list} = resp.body
              $('#RecommendList').html(template('RecommendTemplate', { list }))
            }
          })
        }

        // 商品列表渲染
        getTabs() {
          request.getTabs().then(resp => {
            if (resp.code === 200) {
              let {list} = resp.data
              // list = list.slice(1)
              const id = window.location.hash.slice(1)
              $('.focus_l').html(template('tabsTemplate', { list, id }))
              this.tablist()
            }
          })
        }

        // 列表详情
        tablist() {
          $('.item').mouseenter(function() {
            $(this).children('.item-list').css({'display':'block'})

            $(this).children('.item-list').css('top',()=>{
              return $(this).offset().top - 175
            })

          })
          $('.item').mouseleave(function() {
            $(this).children('.item-list').css({'display':'none'})
          })
        }

        // 轮播图
        swiper() {
          var mySwiper = new Swiper ('.swiper-container', {
            direction: 'horizontal', // 垂直切换选项
            loop: true, // 循环模式选项
            autoplay:true,

            autoplay: {
              disableOnInteraction: false,
            },
            
            // 如果需要分页器
            pagination: {
              el: '.swiper-pagination',
            },
            
            // 如果需要前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev',
            },
          });

          // console.log($('.swiper-pagination-bullet'))

          $('.swiper-pagination-bullet').click(function(){
            mySwiper.slideTo($(this).index()+1, 1000, false);//切换到第一个slide，速度为1秒
            console.log($(this).index())
          })

          var txtSwiper = new Swiper ('.swiper-container2', {
            direction: 'vertical', // 垂直切换选项
            loop: true, // 循环模式选项
            autoplay:true, 
            autoplay: {
              disableOnInteraction: false,
            },
          })


        }

        // 两侧导航
        navs() {

          $('.leftnav ul li').mouseenter(function () {
            $(this).children('.floornum').hide()
            $(this).children('.ftitle').show()
          })

          $('.leftnav ul li').mouseleave(function () {
            $(this).children('.floornum').show()
            $(this).children('.ftitle').hide()
          })

          $('.rightnav ul li').mouseenter(function () {
            $(this).children('.kind').hide()
            $(this).children('.ftitle').show()
          })

          $('.rightnav ul li').mouseleave(function () {
            $(this).children('.kind').show()
            $(this).children('.ftitle').hide()
          })

        }







      }
      new Index()
    })
  })